import time
from appium import webdriver
from AppTest.page.clock_page import ClockPage
from AppTest.page.main_page import MainPage
from AppTest.page.rule_page import RulePage
from AppTest.page.work_page import WorkPage


class estPage:

    def setup(self):
        caps = {"platformName": "Android",
                "appPackage": "com.tencent.wework",
                "appActivity": ".launch.LaunchSplashActivity",
                "deviceName": "127.0.0.1:5555",
                "noReset": True,
                "ensureWebviewsHavePages": True}

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
        self._IMPLICI_WAIT = 10
        self.driver.implicitly_wait(self._IMPLICI_WAIT)

    def teardown(self):
        time.sleep(2)
        self.driver.quit()

    def test_clock_addrule(self):
        mp = MainPage(self.driver)
        mp.ToWorkbench()
        wp = WorkPage(self.driver)
        wp.ToClock()
        cp = ClockPage(self.driver)
        cp.click_newrule()
        cp.click_clockpeople()
        cp.click_department()
        cp.click_choosepeople("郝时迈")
        cp.click_confirm()
        cp.click_rulename()
        cp.input_rulename("打卡")
        cp.click_confirm()
        cp.click_ruletype()
        cp.choose_ruletype("自由上下班")
        cp.click_position()
        cp.click_confirm()
        cp.click_save()
        cp.click_savenow()
        cp.click_confirm()

    def test_clockdeleterule(self):
        mp = MainPage(self.driver)
        mp.ToWorkbench()
        wp = WorkPage(self.driver)
        wp.ToClock()
        cp = ClockPage(self.driver)
        cp.to_rule()
        rp = RulePage(self.driver)
        rp.click_ruledetail()
        rp.click_delete()
        rp.click_savenow()
        rp.click_confirm()

    def test_clock(self):
        mp = MainPage(self.driver)
        mp.ToWorkbench()
        wp = WorkPage(self.driver)
        wp.ToClock()
        cp = ClockPage(self.driver)
        cp.click_wc()
        cp.clock()
